package gameDisplayer;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;


/**
 * Creates an component that is a viewer onto an animation.
 * 
 * @author Robert C. Duvall, edited heavily by Kannan Raju
 */
@SuppressWarnings("serial")
public class Canvas extends JComponent {
    // user's graph to be drawn on
    private Game myGame;

    /**
     * Initializes the canvas.
     * 
     * @param size sets size of Canvas
     * @param g the Visualization to be created (Bar or Pie Chart)
     */
    public Canvas (Dimension size, Game g) {
        // request component size
        setPreferredSize(size);
        requestFocus();
        myGame = g;
    }

    /**
     * Paint the contents of the canvas.
     * 
     * Never called by you directly, instead called by Java runtime
     * when area of screen covered by this container needs to be
     * displayed (i.e., creation, uncovering, change in status)
     * 
     * @param pen used to paint shape on the screen
     */
    @Override
    public void paintComponent (Graphics pen) {
        myGame.paintComponent((Graphics2D) pen, getSize());
    }

}
